package in.muton.edushare.pages.user;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.components.alertpanel.AlertPanel;
import in.muton.edushare.components.messaging.recievepanel.IncomingMessagesPanel;
import in.muton.edushare.components.messaging.sendpanel.ActionPanel;
import in.muton.edushare.components.tasks.electives.ElectiveMainPanel;
import in.muton.edushare.components.tasks.invitations.InvitationsPanel;
import in.muton.edushare.components.tasks.invitations.ThirdPartyCourseInvite;
import in.muton.edushare.components.tasks.invitations.ThirdPartyDeptInvite;
import in.muton.edushare.components.tasks.invitations.ThirdPartyGroupInvite;
import in.muton.edushare.components.tasks.schedules.SchAcceptPanel;
import in.muton.edushare.processing.objects.UserDataHandler;
import in.muton.edushare.wicket.models.CayenneModel;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.model.IModel;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Universities;

public class UserPage extends UserBase {

	public UserPage(PageParameters params) {
		super(params);
		add(new ActionPanel("actionPanel", getModel().getObject(), this));
		add(new IncomingMessagesPanel("msgPanel", getModel().getObject()));
		boolean electiveTime = false;
		List<IModel<Universities>> univList = new UserDataHandler(getModel())
				.getUniv().getObject();
		for (IModel<Universities> univ : univList) {
			if (univ.getObject().getElectiveSelectionTime() == Universities.UNIV_ALLOW_ELECTIVE_SELECTION)
				electiveTime = true;
		}

		if (electiveTime)
			add(new ElectiveMainPanel("electivePanel", getModel(),this));
		else
			add(new EmptyPanel("electivePanel"));

		WebMarkupContainer wmc = new WebMarkupContainer("alertPanel2");
		add(wmc.setVisible(getLoggedInUser() == getModel().getObject()));
		wmc.add(new AlertPanel("alertPanel", new CayenneModel<Object>(getModel()
				.getObject())).setRenderBodyOnly(true));
		add(new InvitationsPanel("invitationPanel", getModel()));
		if (EduShareSession.get().getLoggedInUser() == getModel().getObject())
			add(new SchAcceptPanel("scheduleAcceptPanel", getModel()));
		else
			add(new EmptyPanel("scheduleAcceptPanel"));
		
		add(new ThirdPartyCourseInvite("TPCourseInvite", getModel(), this));
		add(new ThirdPartyDeptInvite("TPDeptInvite", getModel(), this));
		add(new ThirdPartyGroupInvite("TPGroupInvite", getModel(), this));
	}

	@Override
	public String getPageTitle() {
		return getModel().getObject().getCompleteUserName() + " | Home | "
				+ ApplicationConstants.APPLICATION_NAME;
	}

	@Override
	public String getActivePage() {
		return "UserUpdates";
		
	}

	@Override
	public String getUserRole() {
		if (EduShareSession.get().getLoggedInUser() == getModel().getObject())
			return " : Home";
		else
			return "";
	}
}
